﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using KPIS.DBM;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.DAL
{
    public class ActivityTypeDAL
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, ConfigurationSettings.AppSettings["ConnectionString"].ToString());
        ConvertNullable cn = new ConvertNullable();

        public DataSet GetDataActType(Nullable<int>act_type_seq)
        {
            DataSet ds = new DataSet();
            dbManager.Open();
            dbManager.CreateParameters(2);
            dbManager.AddParameters(0, "@act_type_seq", act_type_seq);
            dbManager.AddParameters(1, "@record_status", SystemInfo._ActiveRecordStatus);

            string sql = "SELECT at.act_type_seq as Sequence"
                        + ", at.act_type_descr as Name"
                        + ", at.remark"
                        + " FROM hrm_ac_activity_types at"
                        + " WHERE at.record_status = @record_status"
                        + (act_type_seq != null ? " AND at.act_type_seq = @act_type_seq " : "");

            ds = dbManager.ExecuteDataSet(CommandType.Text, sql);
            dbManager.Dispose();
            return ds;
        }
        public void Insert(string act_type_descr, string remark, int created_by)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(5);

                dbManager.AddParameters(0, "@act_type_descr", act_type_descr);
                dbManager.AddParameters(1, "@remark", remark);
                dbManager.AddParameters(2, "@record_status", SystemInfo._ActiveRecordStatus);
                dbManager.AddParameters(3, "@created_by", created_by);
                dbManager.AddParameters(4, "@created_when", DateTime.Today);

                strSQL = "INSERT INTO hrm_ac_activity_types"
                    + "(act_type_descr"
                    + ", remark"
                    + ", record_status"
                    + ", created_by"
                    + ", created_when)"
                    + " VALUES (@act_type_descr"
                    + ", @remark"
                    + ", @record_status"
                    + ", @created_by"
                    + ", @created_when)";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
        public void Update(int act_type_seq, string act_type_descr, string remark, int updated_by)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(5);

                dbManager.AddParameters(0, "@act_type_seq", act_type_seq);
                dbManager.AddParameters(1, "@act_type_descr", act_type_descr);
                dbManager.AddParameters(2, "@remark", remark);
                dbManager.AddParameters(3, "@updated_by", updated_by);
                dbManager.AddParameters(4, "@updated_when", DateTime.Today);

                strSQL = "UPDATE hrm_ac_activity_types"
                    + " SET act_type_descr = @act_type_descr"
                    + ", remark = @remark"
                    + ", updated_by = @updated_by"
                    + ", updated_when = @updated_when"
                    + " WHERE act_type_seq = @act_type_seq";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
        public void Delete(int act_type_seq, int updated_by)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(4);

                dbManager.AddParameters(0, "@act_type_seq", act_type_seq);
                dbManager.AddParameters(1, "@record_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(2, "@updated_by", updated_by);
                dbManager.AddParameters(3, "@updated_when", DateTime.Today);

                strSQL = "UPDATE hrm_ac_activity_types"
                    + " SET record_status = @record_status"
                    + ", updated_by = @updated_by"
                    + ", updated_when = @updated_when"
                    + " WHERE act_type_seq = @act_type_seq";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
    }
}
